package com.deliccio.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.deliccio.connect.DAO;
import com.deliccio.dao.MenuDAO;
import com.deliccio.entitys.Menu;
import com.deliccio.entitys.Parametros;

@Repository("MenuDAO")
public class MenuDAOImpl extends DAO<Menu> implements MenuDAO{
	
	@Override
	public List<Menu> obtenerMenusSinSession(){
		sqlQuery=" select p " +
				 " from Menu p where p.todos=:todos and p.idMenuPadre.id=0 and p.id>0 ";
		q=em.createQuery(sqlQuery);
		q.setParameter("todos",true);
		return q.getResultList();
	}

	@Override
	public List<Menu> obtenerMenusxPerfil(Integer id){
		
		System.out.println("perfil: "+id);		
		sqlQuery=" select p  from Menu p where p.idMenuPadre.id=0 and " +
				 " p.id in ( select m.id from Parametros p left join p.menuList m where p.id=:id ) ";
		q=em.createQuery(sqlQuery);
		q.setParameter("id",id);
		List<Menu> lst=q.getResultList();	
		System.out.println(" lst menus: "+lst);
		return lst;
	}

}
